package com.example.qx.adapter;

import android.annotation.SuppressLint;
import android.content.Context;
import android.content.Intent;
import android.view.GestureDetector;
import android.view.LayoutInflater;
import android.view.MotionEvent;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import com.example.qx.R;
import com.example.qx.faxiana.chedui;
import com.example.qx.faxiana.qxq;
import com.example.qx.lei.itemfaxian;

import java.util.List;

public class faxianadapter extends RecyclerView.Adapter<faxianadapter.faxianHolder> {

private Context context;
private List<itemfaxian> list ;

    public faxianadapter(List<itemfaxian> list, Context context){
        this.context=context;
        this.list=list;
    }
    @NonNull
    @Override
    public faxianHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        View view= LayoutInflater.from(parent.getContext()).inflate(R.layout.itemfaxian,parent,false);
        return  new faxianadapter.faxianHolder(view);
    }


    @SuppressLint("ClickableViewAccessibility")
    @Override
    public void onBindViewHolder(@NonNull faxianadapter.faxianHolder holder, int position) {
       itemfaxian faxian=list.get(position);
         holder.textView.setText(faxian.getName());
         GestureDetector gestureDetector=new GestureDetector(context,new GestureDetector.SimpleOnGestureListener(){
             @Override
             public boolean onSingleTapConfirmed(MotionEvent e){
                  switch (faxian.getId()){
                      case 1:Intent intent1=new Intent(context,qxq.class);
                              context.startActivity(intent1);
                              break;
                      case 2:Intent intent2=new Intent(context, chedui.class);
                              context.startActivity(intent2);
                  }
                 return true;
             }
         });
          holder.textView.setOnTouchListener(new View.OnTouchListener() {
              @Override
              public boolean onTouch(View v, MotionEvent event) {
                  gestureDetector.onTouchEvent(event);
                  return true;
              }
          });

    }

    @Override
    public int getItemCount() {
        return list.size();
    }
    public static class  faxianHolder extends RecyclerView.ViewHolder{
        private TextView textView;
          public faxianHolder(View v){
              super(v);
              textView=v.findViewById(R.id.faxain);
          }

    }
}
